package leetcode.code;

import java.util.LinkedList;
import java.util.List;

/**
 * @author : zx
 * @version V1.0
 */
public class medium_设计浏览器浏览历史记录 {

    class BrowserHistory {

        List<String> l;
        int curr;

        public BrowserHistory(String homepage) {
            l = new LinkedList<>();
            curr = 0;
            l.add(homepage);
        }

        public void visit(String url) {
            if (curr < l.size()-1){
                l = l.subList(0, curr+1);
            }
            curr++;
            l.add(url);
        }

        public String back(int steps) {
            curr = curr-steps >= 0 ? curr-steps : 0;
            return l.get(curr);
        }

        public String forward(int steps) {
            curr = curr+steps <= l.size()-1 ? curr+steps : l.size()-1;
            return l.get(curr);
        }
    }

/**
 * Your BrowserHistory object will be instantiated and called as such:
 * BrowserHistory obj = new BrowserHistory(homepage);
 * obj.visit(url);
 * String param_2 = obj.back(steps);
 * String param_3 = obj.forward(steps);
 */
}
